lobsterh5.main({
    data: {
        id: 0,
        eid:0,
        info: null
    },
    pageload() {
        var self = this;
        this.data.id = lobsterh5.GetUrlParam('id');
        self.getinfo();
        self.initevent();
    },
    initevent() {
        var self = this;

        $(".weui-rater a").click(function () {
            var index = $(this).index();  //当前点击

            for (var i = 0; i <= index; i++) {
                $(".weui-rater a").eq(i).addClass('on');
            }
            for (var j = index; j <= 5; j++) {
                $(".weui-rater a").eq(j).removeClass('on');
            }
            $(this).addClass('on');
            $("#scorenum").val($(this).data('num'));
        });

        $('#btnSave').click(function () {
            var data = {
                ID:self.data.eid,
                RecordId: self.data.info.Id,
                OrderNo: self.data.info.OrderNo,
                EmpId: self.data.info.EmpId,
                PatientId: self.data.info.PatientId,
                Satisfaction: $("#scorenum").val(),
                EvaluateContent: $("#txtContent").val(),
                DocName:self.data.info.EmpName,
                PatName:self.data.info.PatName
            }

            lobsterh5.POSTAPI('tsevaluation.saveevaluation', data).then(retdata => {
                $.toast("评价保存成功", 'text');
                setTimeout(function () {
                    window.history.back();
                }, 1000)
            })
        })
    },
    getinfo() {
        var self = this;
        lobsterh5.GETAPI('tsevaluation.getmedrecord', { id: self.data.id }).then(retdata => {
            self.data.info = retdata.info;
            $('#info').html('医生:' + retdata.info.EmpName + ',订单号:' + retdata.info.OrderNo);
        });

        lobsterh5.GETAPI('tsevaluation.getevaluation', { RecordId: self.data.id }).then(retdata => {
            if (retdata.evaluation) {
                self.data.eid=retdata.evaluation.ID;
                var status = retdata.evaluation.Status;
                $('#evaluation').html('状态:' + (status == 0 ? '未发布' : '已发布'));
                $("#scorenum").val(retdata.evaluation.Satisfaction);
                $("#txtContent").val(retdata.evaluation.EvaluateContent);
                for (var i = 0; i < parseInt(retdata.evaluation.Satisfaction); i++) {
                    $(".weui-rater a").eq(i).addClass('on');
                }
                if(status==1){
                    $('#btnSave').hide();
                }
            } else {
                $('#evaluation').html('状态:待评价');
            }
        })
    }
});

function textarea(input) {
    var content = $(input);
    var max = content.next().find('i').text();
    var value = content.val();
    if (value.length > 0) {

        value = value.replace(/\n|\r/gi, "");
        var len = value.length;
        content.next().find('span').text(len);
        if (len > max) {
            content.next().addClass('f-red');
        } else {
            content.next().removeClass('f-red');
        }
    }
}


function cleararea(obj) {
    $(obj).prev().find('.weui-textarea').val("").next().find("span").text(0);
    return false;
}